package com.sunny;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Author zsunny
 * @Date 2018/9/20 15:37
 * @Mail zsunny@yeah.net
 */
public class CglibProxyHandler implements MethodInterceptor {

    private Object proxy;

    public CglibProxyHandler(Object proxy) {
        this.proxy = proxy;
    }

    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy)
            throws Throwable {
        doBefore();
        Object res = methodProxy.invokeSuper(o, objects);
        doAfter();
        return res;
    }

    public void doBefore(){
        System.out.println("do before...");
    }

    public void doAfter(){
        System.out.println("do after...");
    }
}
